//
//  WHCodeInfoCell.m
//  SquirrelSeller
//
//  Created by 邓伟浩 on 2019/1/14.
//  Copyright © 2019 邓伟浩. All rights reserved.
//

#import "WHCodeInfoCell.h"

@implementation WHCodeInfoCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self setUpCodeInfoUI];
    }
    return self;
}

- (void)setUpCodeInfoUI {
    [self.contentView addSubview:({
        _tipsLabel = [[UILabel alloc] init];
        _tipsLabel.textAlignment = NSTextAlignmentLeft;
        _tipsLabel.font = SYSTEMFONT(kRealwidth(16));
        _tipsLabel.textColor = CFontTitleBlackColor;
        _tipsLabel;
        
    })];
    
    [_tipsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView.mas_left).offset(kRealwidth(15));
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.height.mas_equalTo(kRealwidth(16));
    }];
    [_tipsLabel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
    
    [self.contentView addSubview:({
        _rightTipsButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_rightTipsButton setTitleColor:CMDarkOrangeColor forState:UIControlStateNormal];
        _rightTipsButton.titleLabel.font = SYSTEMFONT(kRealwidth(15));
        
        _rightTipsButton;
    })];
    
    [_rightTipsButton setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
    [_rightTipsButton setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
    
    [_rightTipsButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.contentView.mas_right).offset(-kRealwidth(17));
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.height.mas_equalTo(kRealwidth(50));
    }];
    
    
    [self.contentView addSubview:({
        _messageField = [[UITextField alloc] init];
        _messageField.textAlignment = NSTextAlignmentLeft;
        _messageField.font = SYSTEMFONT(kRealwidth(15));
        _messageField.textColor = CFontTitleBlackColor;
        _messageField;
        
    })];
    
    [_messageField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(_rightTipsButton.mas_left).offset(-kRealwidth(20));
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.height.mas_equalTo(self.mas_height);
        make.left.mas_equalTo(_tipsLabel.mas_right).offset(kRealwidth(40));
    }];
    [_messageField setContentHuggingPriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];
    
    kWeakSelf(self);
    _messageField.keyboardType = UIKeyboardTypeNumberPad;
    _messageField.yb_inputCP = YBInputControlProfile.creat.set_maxLength(6).set_regularStr(@"^[0-9]{0,6}+$").set_textChanged(^(id obj) {
        if (weakself.textChangeBlock) {
            weakself.textChangeBlock([obj valueForKey:@"text"]);
        }
    });
    [_rightTipsButton addTarget:self action:@selector(rightTipsClicked:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)rightTipsClicked:(id)sender {
    if (self.rightBtnClicked) {
        self.rightBtnClicked();
    }
}

- (void)setInputTextPlaceHolder:(NSString *)placeHolderStr {
    NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:placeHolderStr attributes:@{NSForegroundColorAttributeName:CFontContentLightGrayColor, NSFontAttributeName:self.messageField.font}];
    self.messageField.attributedPlaceholder = attrString;
}

- (void)prepareForReuse {
    _messageField.text = @"";
    _tipsLabel.text = @"";
    
    [super prepareForReuse];
}


@end
